********************************************************************************
* This program generates indirect domestic energy prices
*
* Authors: Karl
* Updated: 2019 0424
*
* Edited: Aug 2020
********************************************************************************


*************************************************************************
* 				PART I . claim inputs and outputs
*************************************************************************
clear programs

// Input data: 

// intensities.
// created in 3_2_1_gen_energyintensities.do
global ENERGY_I = "$EI/energy_intensity_2007_naics2007.dta"

// IO energy intensity weighted
// created in 3_2_1_gen_energyintensities_IO.do
global ENERGY_I_IO = "$IO/IO_energyintensity.dta"

// energy prices: 
// created in 3_1_1_gen_energyprice_domestic.do
global ENERGY_P = "$energy_price/energy_price_industry_year.dta"

// Output data:
global NAICS_PRICE = "$energy_price/energy_price_industry_year_indirect.dta"


tempfile price_clean
use "$ENERGY_P", clear
drop census_naics
drop naics
rename naics2007 naics
quietly save `price_clean'
	
rename naics naics_row
joinby naics_row using "$ENERGY_I_IO"

gen ind_price = io_v_norm*price_TIV
		
collapse (sum) ind_price, by(naics year)
merge 1:1 naics year using `price_clean', keepusing(price_TIV) nogen keep(match)

//add in industrylabels
merge m:1 naics using "$ENERGY_I", nogen norep keepus(naics2012 industryname2007)

label var ind_pric "indirect price [time-invariant fuel share] for NAICS2012 industries, $ per mi"
save "$NAICS_PRICE", replace
